/*
 * Utilities.h
 *
 *  Created on: Aug 29, 2012
 *      Author: alberto
 */

#ifndef UTILITIES_H_
#define UTILITIES_H_

#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <math.h>
#include <jpeglib.h>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;
using namespace std;

bool compareMatch(DMatch A, DMatch B);
double calculateAngle(double x1, double y1, double x2, double y2);
int* generateRandomIndexes(int boundary);
void calculateCumulativeDistribution(const Mat& histogram, size_t totalSize, vector<double>& cumulativeDistribution);
void equalizeHistogram(const Mat& histogram, size_t totalSize, vector<size_t>& mapping, vector<double>& cumulativeDistribution, Mat& eqHistogram);
size_t findNearest(const vector<double>& elements, double k);
size_t findNearest2(double k, const vector<double>& elements);
void createHistogramMatchingMap(const vector<double>& cdf_im, const vector<double>& cdf_target, vector<size_t>& esp_mapping);
void histogramMatching(Mat& imageSrc, const vector<size_t>& eq_mapping, const vector<size_t>& esp_mapping, Mat& imageDst);
void equalizeColorImage(const Mat& image, Mat& eqImage);
double correlationCoefficient(const Mat& A, const Mat& B);
double meanSqrdError(const Mat& A, const Mat& B);
bool cmpPairSmallest(const pair<int, float> a, const pair<int, float> b);
bool cmpPairBiggest(const pair<int, float> a, const pair<int, float> b);
void readDecompInfo(j_decompress_ptr dec_info, string imname);
void jpegRecompression(const Mat &OriginalIm, string estName, Mat &recompIm);
template <class itr>
void printVector(string name, itr bg, itr ed);
void matchColor(const Mat &src, const Mat &target, Mat &result);

#endif /* UTILITIES_H_ */
